/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package test;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author kevin
 */
public class MyJWindow extends javax.swing.JWindow {
    private int duration;
    int livetime;
    int currenttime;
    int iconWidth = 480;
    int iconHeight = 283;
    Image im;
    public MyJWindow(int time){
        duration = time;
        livetime = duration/1000;
        im = this.getToolkit().getImage("src/image/hua.jpg");
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (d.width-iconWidth)/2;
        int y = (d.height-iconHeight)/2;
        currenttime = livetime;
        //设置窗口的大小和位置
        this.setBounds(x, y, iconWidth, iconHeight);
        this.setVisible(true);
        this.setAlwaysOnTop(true);
    }
    public void showWindow(){
        for(int i=0;i<livetime;i++){
            try {
                currenttime = livetime - i;
                repaint(); /////重绘整个窗体
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(MyJWindow.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        this.setVisible(false);
        System.exit(0);
    }

    @Override
    public void update(Graphics g){
        paint(g);
    }

    @Override
    public void paint(Graphics g){
        g.drawImage(im, 0, 0, this);
        Font font = new Font("宋体",Font.PLAIN,26);
        g.setFont(font);
        g.setColor(Color.orange);
        g.drawString("该窗体在"+currenttime+"秒钟后消失", 80, 150);
    }

    public static void main(String[] args){
        MyJWindow w = new MyJWindow(2000);
        w.showWindow();

    }
}
